package cc.rengu.oltp.service.common.enums;

import cc.rengu.oltp.utility.util.StringUtil;

/**
 * 交易状态枚举
 * Created by 王成 on 2018/4/9.
 */
public enum TransStatusEnum {
    TRANS_INIT("0", "初始状态"),
    TRANS_SUCC("1", "成功"),
    SYSTEM_REJECT("2", "交易失败"),
    TRANS_TIMEOUT("3", "超时/未知"),
    ;
    private String status;
    private String desc;

    TransStatusEnum(String status, String desc) {
        this.status = status;
        this.desc = desc;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * 根据错误状态码获取交易状态枚举
     *
     * @param status 交易状态
     * @return 交易状态枚举
     */
    public static TransStatusEnum getTransStatusEnum(String status) {
        for (TransStatusEnum transStatusEnum : TransStatusEnum.values()) {
            if (status.equals(transStatusEnum.getStatus())) {
                return transStatusEnum;
            }
        }
        return null;
    }
}
